/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.ajz.web;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.ajz.entity.AjzCompanyInfo;
import com.jeesite.modules.ajz.entity.AjzRecordProcess;
import com.jeesite.modules.ajz.service.AjzCompanyInfoService;
import com.jeesite.modules.ajz.service.AjzRecordProcessService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 历史记录Controller
 * @author cww
 * @version 2019-01-11
 */
@Controller
@RequestMapping(value = "${adminPath}/ajz/ajzRecordProcess")
public class AjzRecordProcessController extends BaseController {

	@Autowired
	private AjzRecordProcessService ajzRecordProcessService;

	@Autowired
	private AjzCompanyInfoService ajzCompanyInfoService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public AjzRecordProcess get(String id, boolean isNewRecord) {
		return ajzRecordProcessService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("ajz:ajzRecordProcess:view")
	@RequestMapping(value = {"list", ""})
	public String list(AjzRecordProcess ajzRecordProcess,  HttpServletRequest request, HttpServletResponse response,Model model) {
		String base_id = request.getParameter("base_id");
		System.out.println(base_id);

		AjzCompanyInfo ajzCompanyInfo = ajzCompanyInfoService.get(base_id);
		ajzRecordProcess.setAjzCompanyInfo(ajzCompanyInfo);

		model.addAttribute("ajzRecordProcess", ajzRecordProcess);
		return "modules/ajz/ajzRecordProcessList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("ajz:ajzRecordProcess:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<AjzRecordProcess> listData(AjzRecordProcess ajzRecordProcess, HttpServletRequest request, HttpServletResponse response) {
		ajzRecordProcess.setPage(new Page<>(request, response));
		Page<AjzRecordProcess> page = ajzRecordProcessService.findPage(ajzRecordProcess); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("ajz:ajzRecordProcess:view")
	@RequestMapping(value = "form")
	public String form(AjzRecordProcess ajzRecordProcess, Model model) {
		model.addAttribute("ajzRecordProcess", ajzRecordProcess);
		return "modules/ajz/ajzRecordProcessForm";
	}

	/**
	 * 保存历史记录
	 */
	@RequiresPermissions("ajz:ajzRecordProcess:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated AjzRecordProcess ajzRecordProcess) {
		ajzRecordProcessService.save(ajzRecordProcess);
		return renderResult(Global.TRUE, text("保存历史记录成功！"));
	}
	
	/**
	 * 停用历史记录
	 */
	@RequiresPermissions("ajz:ajzRecordProcess:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(AjzRecordProcess ajzRecordProcess) {
		ajzRecordProcess.setStatus(AjzRecordProcess.STATUS_DISABLE);
		ajzRecordProcessService.updateStatus(ajzRecordProcess);
		return renderResult(Global.TRUE, text("停用历史记录成功"));
	}
	
	/**
	 * 启用历史记录
	 */
	@RequiresPermissions("ajz:ajzRecordProcess:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(AjzRecordProcess ajzRecordProcess) {
		ajzRecordProcess.setStatus(AjzRecordProcess.STATUS_NORMAL);
		ajzRecordProcessService.updateStatus(ajzRecordProcess);
		return renderResult(Global.TRUE, text("启用历史记录成功"));
	}
	
	/**
	 * 删除历史记录
	 */
	@RequiresPermissions("ajz:ajzRecordProcess:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(AjzRecordProcess ajzRecordProcess) {
		ajzRecordProcessService.delete(ajzRecordProcess);
		return renderResult(Global.TRUE, text("删除历史记录成功！"));
	}
	
}